﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AESUtil
{
    internal class Base64Util
    {
        private static string getOriginBase64String(string base64String)
        {
            int length = base64String.Length;
            int fix = length % 4;
            if (fix != 0)
            {
                fix = 4 - fix;
                string fixStr = "";
                while (fix > 0)
                {
                    fixStr += "=";
                    fix--;
                }
                base64String += fixStr;
            }
            if (base64String.Contains("-") || base64String.Contains("_"))
            {
                base64String = base64String.Replace("-", "+").Replace("_", "/");
            }
            return base64String;
        }
        public static byte[] getByteArrayFromBase64String(string base64String)
        {
            base64String = getOriginBase64String(base64String);
            return Convert.FromBase64String(base64String);
        }
        public static string getStringFromBase64String(string base64String)
        {
            return Encoding.UTF8.GetString(getByteArrayFromBase64String(base64String));
        }
    }
}
